package com.jizhangben.controller;

import com.jizhangben.pojo.AccountPojo;
import com.jizhangben.service.AccountService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/details")
public class DetailsAccountServlet extends HttpServlet {
    private AccountService accountService=new AccountService();
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int tableId = Integer.parseInt(req.getParameter("tableId"));
        AccountPojo accountPojo=accountService.getByIdAcount(tableId);
        req.setAttribute("tableName",accountPojo.getName());
        req.setAttribute("tableMoney",accountPojo.getMoney());
        req.setAttribute("tableDetails",accountPojo.getDetails());
        req.setAttribute("tableTime",accountPojo.getTime());
        req.getRequestDispatcher("views/details.jsp").forward(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("views/details.jsp").forward(req, resp);
    }
}
